package secretaryGUI;


import java.awt.Point;
import java.sql.SQLException;

import secretary.defineSemester;

import com.sun.rowset.CachedRowSetImpl;

import basic.ClientConsole;
import flexibility.userData;
import guiCode.secretaryScreenCode;

public class addStudentToClass {
	secretaryScreenCode ssc;
	secretaryAlerts sa = new secretaryAlerts();
	userData moveStudent = new userData();
	userData student = new userData();
	private updateUpperTableEntries UUTE = new updateUpperTableEntries();
	private updateLowerTableEntries ULTE = new updateLowerTableEntries();
	private defineSemester ds = new defineSemester();
	
	public void click(secretaryScreenCode code, createSecretaryWindow csw,
			int studentID, int classID, ClientConsole secretaryConnection,
			CachedRowSetImpl crs, int semester, Point point) {
		ssc = code;
		if(ssc.getEditMode()==8){
			//this is the mode for manual edit of the student
			//this will print all the student's courses currently, on the  lower table
			csw.table_1.setEnabled(true);
			student.deleteAll();
			student.addData(252);
			student.addData(1);
			student.addData(csw.table_1.getValueAt(csw.table_1.rowAtPoint(point), 0));
			secretaryConnection.acceptMsg(student);
			crs = secretaryConnection.getResults();
			ULTE.update(csw, crs);
		}
		
		if(ssc.getEditMode()==4){
			switch(semester){
			case 1:
				moveStudent.deleteAll();
				moveStudent.addData(15);
				moveStudent.addData(1);
				secretaryConnection.acceptMsg(moveStudent);
				crs = secretaryConnection.getResults();
				try {
					crs.next();
					semester = Integer.parseInt(crs.getString(1));
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				break;
			case 0:
				moveStudent.deleteAll();
				moveStudent.addData(82);
				moveStudent.addData(1);
				secretaryConnection.acceptMsg(moveStudent);
				crs = secretaryConnection.getResults();
				try {
					crs.next();
					semester = Integer.parseInt(crs.getString(1));
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			break;
			}
			
			moveStudent.deleteAll();
			moveStudent.addData(90);//this will add the student to the class in students table
			moveStudent.addData(0);
			moveStudent.addData(classID);
			moveStudent.addData(semester);
			moveStudent.addData(studentID);
			moveStudent.addData(ds.identify(ssc.getSemesterForEdit(), secretaryConnection, crs));
			secretaryConnection.acceptMsg(moveStudent);
			crs = secretaryConnection.getResults();
			//this will add the student to the class in students table
			moveStudent.deleteAll();
			moveStudent.addData(166);
			moveStudent.addData(0);
			moveStudent.addData(studentID);
			secretaryConnection.acceptMsg(moveStudent);
			crs = secretaryConnection.getResults();
			moveStudent.deleteAll();
			moveStudent.addData(167);
			moveStudent.addData(0);
			moveStudent.addData(studentID);
			moveStudent.addData(classID);
			moveStudent.addData(semester);
			secretaryConnection.acceptMsg(moveStudent);
			crs = secretaryConnection.getResults();
			
			moveStudent.deleteAll();
			moveStudent.addData(87);
			moveStudent.addData(1);// this is for read
			moveStudent.addData(semester);
			moveStudent.addData(classID);
			secretaryConnection.acceptMsg(moveStudent);
			crs = secretaryConnection.getResults();
			UUTE.update(csw, crs);
			ssc.getAllOtherStudents(classID);
			csw.btnRemoveStudentFrom.setEnabled(true);
		}
		}
		
		
	}

